import { BasicColumn, FormSchema } from '@/components/Table';
import { getTemplateList } from '@/api/template/template';

export const columns: BasicColumn[] = [
  {
    title: '页面名称',
    dataIndex: 'name',
    width: 120,
  },
  {
    title: '页面类型',
    dataIndex: 'type',
    width: 120,
    customRender: ({ record }) => {
      const typeMap = {
        show: '展示页',
        content: '内容页',
      };
      return typeMap[record.type] || record.type;
    },
  },
  {
    title: '模板',
    dataIndex: 'template_name',
    width: 120,
  },
  {
    title: 'URL',
    dataIndex: 'url',
    width: 180,
  },
  {
    title: '排序',
    dataIndex: 'sort',
    width: 80,
  },
  {
    title: '显示',
    dataIndex: 'is_show',
    width: 80,
    customRender: ({ record }) => {
      return record.is_show ? '是' : '否';
    },
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 80,
    customRender: ({ record }) => {
      return record.status === 10 ? '启用' : '禁用';
    },
  },
  {
    title: '创建时间',
    dataIndex: 'created_at',
    width: 180,
  },
  {
    title: '更新时间',
    dataIndex: 'updated_at',
    width: 180,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'template_id',
    label: '模板',
    component: 'ApiSelect',
    componentProps: {
      api: getTemplateList,
      resultField: 'list',
      labelField: 'name',
      valueField: 'id',
    },
    colProps: { span: 8 },
  },
  {
    field: 'name',
    label: '页面名称',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'type',
    label: '页面类型',
    component: 'Select',
    componentProps: {
      options: [
        { label: '展示页', value: 'show' },
        { label: '内容页', value: 'content' },
      ],
    },
    colProps: { span: 8 },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'name',
    label: '页面名称',
    component: 'Input',
    required: true,
    colProps: { span: 24 },
  },
  {
    field: 'type',
    label: '页面类型',
    component: 'Select',
    componentProps: {
      options: [
        { label: '展示页', value: 'show' },
        { label: '内容页', value: 'content' },
      ],
    },
    required: true,
    colProps: { span: 24 },
  },
  {
    field: 'template_id',
    label: '模板',
    component: 'ApiSelect',
    componentProps: {
      api: getTemplateList,
      resultField: 'list',
      labelField: 'name',
      valueField: 'id',
      params: { status: 10 },
    },
    required: true,
    colProps: { span: 24 },
  },
  {
    field: 'url',
    label: '页面URL',
    component: 'Input',
    required: true,
    colProps: { span: 24 },
  },
  {
    field: 'html',
    label: 'HTML内容',
    component: 'InputTextArea',
    required: true,
    componentProps: {
      rows: 10,
    },
    colProps: { span: 24 },
  },
  {
    field: 'is_show',
    label: '是否显示',
    component: 'Switch',
    defaultValue: true,
    required: true,
    colProps: { span: 24 },
  },
  {
    field: 'sort',
    label: '排序',
    component: 'InputNumber',
    required: true,
    defaultValue: 0,
    componentProps: {
      min: 0,
    },
    colProps: { span: 24 },
  },
  {
    field: 'status',
    label: '状态',
    component: 'RadioButtonGroup',
    defaultValue: 10,
    required: true,
    colProps: { span: 24 },
    componentProps: {
      options: [
        { label: '启用', value: 10 },
        { label: '禁用', value: 20 },
      ],
    },
  },
];
